{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-8 offset-md-2">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">处理参数配置</h5>
            </div>
            <div class="card-body">
                <form id="configForm">
                    <div class="mb-3">
                        <label class="form-label">基础质量参数</label>
                        <div class="row g-3">
                            <div class="col-md-6">
                                <label class="form-label">质量阈值</label>
                                <input type="number" class="form-control" name="quality_threshold" 
                                       value="{{ config.quality_threshold }}" step="0.1">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">模糊度阈值</label>
                                <input type="number" class="form-control" name="blur_threshold" 
                                       value="{{ config.blur_threshold }}" step="0.1">
                            </div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">人脸检测参数</label>
                        <div class="row g-3">
                            <div class="col-md-6">
                                <label class="form-label">最小人脸比例</label>
                                <input type="number" class="form-control" name="face_ratio_min" 
                                       value="{{ config.face_ratio_min }}" step="0.01">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">最大人脸比例</label>
                                <input type="number" class="form-control" name="face_ratio_max" 
                                       value="{{ config.face_ratio_max }}" step="0.01">
                            </div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">角度限制</label>
                        <div class="row g-3">
                            <div class="col-md-6">
                                <label class="form-label">偏航角范围</label>
                                <div class="input-group">
                                    <input type="number" class="form-control" name="yaw_min" 
                                           value="{{ config.yaw_range[0] }}">
                                    <span class="input-group-text">-</span>
                                    <input type="number" class="form-control" name="yaw_max" 
                                           value="{{ config.yaw_range[1] }}">
                                </div>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">俯仰角范围</label>
                                <div class="input-group">
                                    <input type="number" class="form-control" name="pitch_min" 
                                           value="{{ config.pitch_range[0] }}">
                                    <span class="input-group-text">-</span>
                                    <input type="number" class="form-control" name="pitch_max" 
                                           value="{{ config.pitch_range[1] }}">
                                </div>
                            </div>
                        </div>
                    </div>

                    <button type="submit" class="btn btn-primary">保存配置</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
document.getElementById('configForm').addEventListener('submit', async (e) => {
    e.preventDefault();
    const formData = new FormData(e.target);
    
    try {
        const response = await fetch('/config', {
            method: 'POST',
            body: formData
        });
        
        const data = await response.json();
        if (response.ok) {
            alert('配置已更新');
        } else {
            alert('配置更新失败: ' + data.error);
        }
    } catch (error) {
        console.error('配置更新错误:', error);
        alert('配置更新出错');
    }
});
</script>
{% endblock %} 